/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package camada.apresentacao.financeiro.cheque;

import camada.bancodedados.conexao.Conexao;
import camada.bancodedados.daoimplemente.banco.BancoDAOImpl;
import camada.bancodedados.daoimplemente.cliente.PessoaFisicaDAOImpl;
import camada.bancodedados.daoimplemente.financeiro.cheque.ChequeRecebimentoDAOImpl;
import combomodel.ComboBoxClienteModel;
import combomodel.banco.ComboBoxBancoModel;
import eloma.classe.Cliente;
import eloma.classe.Fornecedor;
import eloma.classe.banco.Banco;
import eloma.classe.cheque.ChequeRecebimento;
import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import javax.swing.JOptionPane;
import javax.swing.border.Border;
import org.jdesktop.swingx.error.ErrorInfo;
import utilitarios.ValidarCMC7;
import utilitarios.erros.MessagemErro;

/**
 *
 * @author Ícaro
 */
public class InternalFrmRecebimentoCheque extends javax.swing.JInternalFrame {

    private static Connection con;

    int index = 0;
    boolean editar = false;
    boolean ePesquisa = false;

    List<ChequeRecebimento> listaChequeRecebimento;

    /**
     * Creates new form internalFrmCadCliente
     */
    public InternalFrmRecebimentoCheque() {
        initComponents();
        carregarCombo();
        capturaDados();
        montarFields(index);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        groupRadio = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtRegistro = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cmCliente = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtValor = new javax.swing.JFormattedTextField();
        jLabel5 = new javax.swing.JLabel();
        cmDataParaBaixa = new com.toedter.calendar.JDateChooser();
        cmDataCadastro = new com.toedter.calendar.JDateChooser();
        cmBanco = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        txtNumeroCheque = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        txtNomeEmitente = new javax.swing.JTextField();
        jSeparator3 = new javax.swing.JSeparator();
        rbDepositado = new javax.swing.JRadioButton();
        cmDataDeposito = new com.toedter.calendar.JDateChooser();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txtRepasseDestinatario = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        cmRepasseFornecedor = new javax.swing.JComboBox();
        rbRepassado = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        cmDataRepasse = new com.toedter.calendar.JDateChooser();
        rbDevolvido = new javax.swing.JRadioButton();
        jLabel12 = new javax.swing.JLabel();
        cmDataDevolucao = new com.toedter.calendar.JDateChooser();
        rbEstoque = new javax.swing.JRadioButton();
        ckCompensado = new javax.swing.JCheckBox();
        txtCMC7 = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        btNaoSeiAinda = new org.jdesktop.swingx.JXHyperlink();
        btNovo = new org.jdesktop.swingx.JXHyperlink();
        btSalvar = new org.jdesktop.swingx.JXHyperlink();
        btEditar = new org.jdesktop.swingx.JXHyperlink();
        btExcluir = new org.jdesktop.swingx.JXHyperlink();
        btCancelar = new org.jdesktop.swingx.JXHyperlink();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        btPrimeiro = new org.jdesktop.swingx.JXHyperlink();
        btAnterior = new org.jdesktop.swingx.JXHyperlink();
        btProximo = new org.jdesktop.swingx.JXHyperlink();
        btUltimo = new org.jdesktop.swingx.JXHyperlink();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jXHyperlink11 = new org.jdesktop.swingx.JXHyperlink();
        jXHyperlink12 = new org.jdesktop.swingx.JXHyperlink();
        jSeparator5 = new javax.swing.JToolBar.Separator();
        txtSair = new org.jdesktop.swingx.JXHyperlink();
        jSeparator4 = new javax.swing.JSeparator();
        SeletorArquivo = new javax.swing.JFileChooser();

        setToolTipText("Cartão Crédito");

        jScrollPane1.setBorder(null);

        jPanel1.setToolTipText("Recebimento de Cheques");

        jLabel1.setText("Registro:");

        txtRegistro.setEnabled(false);

        jLabel22.setText("Banco:");

        jLabel2.setText("Número Cheque:");

        jLabel3.setText("Cliente:");
        jLabel3.setToolTipText("");

        cmCliente.setEnabled(false);

        jLabel4.setText("Valor Cheque:");

        txtValor.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("###0.00"))));
        txtValor.setEnabled(false);

        jLabel5.setText("Data do Cadastro:");

        cmDataParaBaixa.setEnabled(false);

        cmDataCadastro.setEnabled(false);

        cmBanco.setEnabled(false);

        jLabel6.setText("Data para Baixa (Bom Para):");

        txtNumeroCheque.setEnabled(false);

        jLabel7.setText("Nome Emitente:");

        txtNomeEmitente.setEnabled(false);

        groupRadio.add(rbDepositado);
        rbDepositado.setText("Depositado");
        rbDepositado.setEnabled(false);
        rbDepositado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbDepositadoActionPerformed(evt);
            }
        });

        cmDataDeposito.setEnabled(false);

        jLabel8.setText("Data Deposito:");

        jLabel9.setText("Destinatario:");

        txtRepasseDestinatario.setEnabled(false);

        jLabel10.setText("Fornecedor:");

        cmRepasseFornecedor.setEnabled(false);

        groupRadio.add(rbRepassado);
        rbRepassado.setText("Repassado:");
        rbRepassado.setEnabled(false);
        rbRepassado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbRepassadoActionPerformed(evt);
            }
        });

        jLabel11.setText("Data Repasse:");

        cmDataRepasse.setEnabled(false);

        groupRadio.add(rbDevolvido);
        rbDevolvido.setText("Devolvido");
        rbDevolvido.setEnabled(false);
        rbDevolvido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbDevolvidoActionPerformed(evt);
            }
        });

        jLabel12.setText("Data Devolução:");

        cmDataDevolucao.setEnabled(false);

        groupRadio.add(rbEstoque);
        rbEstoque.setSelected(true);
        rbEstoque.setText("Em Estoque");
        rbEstoque.setEnabled(false);
        rbEstoque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbEstoqueActionPerformed(evt);
            }
        });

        ckCompensado.setText("Cheque Compensado?");
        ckCompensado.setEnabled(false);

        try {
            txtCMC7.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##############################")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txtCMC7.setToolTipText("CMC7");
        txtCMC7.setEnabled(false);

        jLabel13.setText("CMC7 - Número Cheque:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel8)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator3)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(rbEstoque)
                                    .addComponent(rbDepositado)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel12)
                                            .addComponent(cmDataDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(rbDevolvido)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addComponent(jLabel11))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtRepasseDestinatario, javax.swing.GroupLayout.PREFERRED_SIZE, 352, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel9)
                                            .addComponent(cmDataRepasse, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(cmRepasseFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(rbRepassado)
                                    .addComponent(jLabel1)
                                    .addComponent(txtRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(cmDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(cmBanco, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jLabel5)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel22)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel6)
                                            .addComponent(cmDataParaBaixa, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(txtNumeroCheque, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel7)
                                            .addComponent(txtNomeEmitente, javax.swing.GroupLayout.PREFERRED_SIZE, 431, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(cmCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(20, 20, 20)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ckCompensado)
                                            .addComponent(cmDataDeposito, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txtValor, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel4))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel13)
                                            .addComponent(txtCMC7, javax.swing.GroupLayout.PREFERRED_SIZE, 277, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(0, 443, Short.MAX_VALUE)))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtRegistro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel22)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmDataCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmBanco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmDataParaBaixa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNumeroCheque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNomeEmitente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel13))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCMC7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(rbEstoque)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbDepositado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addGap(6, 6, 6)
                .addComponent(cmDataDeposito, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(ckCompensado)
                .addGap(8, 8, 8)
                .addComponent(rbRepassado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmDataRepasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmRepasseFornecedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRepasseDestinatario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbDevolvido)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmDataDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jScrollPane1.setViewportView(jPanel1);

        jToolBar1.setFloatable(false);
        jToolBar1.setToolTipText("Cadastro Cliente");

        btNaoSeiAinda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document.png"))); // NOI18N
        btNaoSeiAinda.setText("");
        btNaoSeiAinda.setFocusable(false);
        btNaoSeiAinda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNaoSeiAinda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btNaoSeiAinda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNaoSeiAindaActionPerformed(evt);
            }
        });
        jToolBar1.add(btNaoSeiAinda);

        btNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_add.png"))); // NOI18N
        btNovo.setText("");
        btNovo.setFocusable(false);
        btNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });
        jToolBar1.add(btNovo);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_ok.png"))); // NOI18N
        btSalvar.setText("");
        btSalvar.setEnabled(false);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });
        jToolBar1.add(btSalvar);

        btEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_edit.png"))); // NOI18N
        btEditar.setText("");
        btEditar.setFocusable(false);
        btEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btEditar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEditarActionPerformed(evt);
            }
        });
        jToolBar1.add(btEditar);

        btExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_error.png"))); // NOI18N
        btExcluir.setText("");
        btExcluir.setFocusable(false);
        btExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btExcluirActionPerformed(evt);
            }
        });
        jToolBar1.add(btExcluir);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/cad/document_delete.png"))); // NOI18N
        btCancelar.setText("");
        btCancelar.setEnabled(false);
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });
        jToolBar1.add(btCancelar);
        jToolBar1.add(jSeparator1);

        btPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_rewind.png"))); // NOI18N
        btPrimeiro.setText("");
        btPrimeiro.setFocusable(false);
        btPrimeiro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btPrimeiro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btPrimeiroActionPerformed(evt);
            }
        });
        jToolBar1.add(btPrimeiro);

        btAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_back.png"))); // NOI18N
        btAnterior.setText("");
        btAnterior.setFocusable(false);
        btAnterior.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btAnterior.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAnteriorActionPerformed(evt);
            }
        });
        jToolBar1.add(btAnterior);

        btProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_step_forward.png"))); // NOI18N
        btProximo.setText("");
        btProximo.setFocusable(false);
        btProximo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btProximo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btProximoActionPerformed(evt);
            }
        });
        jToolBar1.add(btProximo);

        btUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/media_fast_forward.png"))); // NOI18N
        btUltimo.setText("");
        btUltimo.setFocusable(false);
        btUltimo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btUltimo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btUltimoActionPerformed(evt);
            }
        });
        jToolBar1.add(btUltimo);
        jToolBar1.add(jSeparator2);

        jXHyperlink11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/document_view.png"))); // NOI18N
        jXHyperlink11.setText("");
        jXHyperlink11.setFocusable(false);
        jXHyperlink11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jXHyperlink11.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jXHyperlink11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXHyperlink11ActionPerformed(evt);
            }
        });
        jToolBar1.add(jXHyperlink11);

        jXHyperlink12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/print/printer.png"))); // NOI18N
        jXHyperlink12.setText("");
        jXHyperlink12.setFocusable(false);
        jXHyperlink12.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jXHyperlink12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jXHyperlink12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXHyperlink12ActionPerformed(evt);
            }
        });
        jToolBar1.add(jXHyperlink12);
        jToolBar1.add(jSeparator5);

        txtSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/internal/move/window_delete.png"))); // NOI18N
        txtSair.setText("");
        txtSair.setFocusable(false);
        txtSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        txtSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        txtSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSairActionPerformed(evt);
            }
        });
        jToolBar1.add(txtSair);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSeparator4))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(287, Short.MAX_VALUE)
                    .addComponent(SeletorArquivo, javax.swing.GroupLayout.PREFERRED_SIZE, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(899, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 645, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(544, Short.MAX_VALUE)
                    .addComponent(SeletorArquivo, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(162, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSairActionPerformed
        try {

            con = Conexao.getCon();
            con.rollback();

            this.setVisible(false);

        } catch (SQLException e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_txtSairActionPerformed

    private void btPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btPrimeiroActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            index = 0;
            montarFields(index);
            ePesquisa = false;
        } else {
            montarFields(0);
            index = 0;
        }
    }//GEN-LAST:event_btPrimeiroActionPerformed

    private void btUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btUltimoActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            index = listaChequeRecebimento.size() - 1;
            montarFields(index);
            ePesquisa = false;
        } else {
            montarFields(listaChequeRecebimento.size() - 1);
            index = listaChequeRecebimento.size() - 1;
        }
    }//GEN-LAST:event_btUltimoActionPerformed

    private void btProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btProximoActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            if (index != (listaChequeRecebimento.size() - 1)) {
                index = index + 1;
                montarFields(index);
            }
            ePesquisa = false;
        } else {
            if (index != (listaChequeRecebimento.size() - 1)) {
                montarFields(index + 1);
                index = index + 1;
            }
        }
    }//GEN-LAST:event_btProximoActionPerformed

    private void btAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAnteriorActionPerformed
        if (ePesquisa == true) {
            capturaDados();
            if (index > 0) {
                index = index - 1;
                montarFields(index);
            } else if (index == 0) {
                index = listaChequeRecebimento.size() - 1;
                montarFields(index);
            }
            ePesquisa = false;
        } else {
            if (index > 0) {
                montarFields(index - 1);
                index = index - 1;
            }
        }
    }//GEN-LAST:event_btAnteriorActionPerformed

    private void jXHyperlink11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXHyperlink11ActionPerformed
        try {

//            DialogPesquisaCliente pesquisa = new DialogPesquisaCliente(null, true);
//            pesquisa.setVisible(true);
//
//            if (pesquisa.getCliente() != null) {
//
//                Cliente u = pesquisa.getCliente();
//
//                listaCliente = new ArrayList<Cliente>();
//                listaCliente.add(u);
//
//                index = 0;
//                montarFields(index);
//
//                ePesquisa = true;
//
//            }
        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_jXHyperlink11ActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed

        habilitaBotao();
        limparTextField();
        habilitarTextFiel();
        
        cmDataCadastro.setDate(new Date(System.currentTimeMillis()));

    }//GEN-LAST:event_btNovoActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed

        desabilitaBotao();
        desabilitarTextFiel();
        montarFields(0);

    }//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try {

            boolean validacao = validarTextField();

            if (validacao == false) {

                ChequeRecebimentoDAOImpl daoChequeRecebimento = new ChequeRecebimentoDAOImpl();
                
                ChequeRecebimento d = new ChequeRecebimento();
                
                d.setDataCadastro(new java.sql.Date(cmDataCadastro.getDate().getTime()));
                
                ComboBoxBancoModel m = (ComboBoxBancoModel) cmBanco.getModel();
                Banco b = (Banco) m.getSelectedItem();
                
                d.setBanco(b);
                d.setDataParaBaixa(new java.sql.Date(cmDataParaBaixa.getDate().getTime()));
                d.setNumeroCheque(txtNumeroCheque.getText());
                d.setNomeEmitente(txtNomeEmitente.getText());
                
                ComboBoxClienteModel n = (ComboBoxClienteModel) cmCliente.getModel();
                Cliente c = (Cliente) n.getSelectedItem();
                
                d.setCliente(c);
                d.setValor(Double.parseDouble(txtValor.getText().replace(",", ".")));
                d.setCMC7(txtCMC7.getText());
                
                if(rbDepositado.isSelected() == true){
                    d.setDataDeposito(new java.sql.Date(cmDataDeposito.getDate().getTime()));
                    d.setCompensado(ckCompensado.isSelected());
                }
                    
                if(rbRepassado.isSelected() == true){
                    d.setDataRepasse(new java.sql.Date(cmDataRepasse.getDate().getTime()));
                    d.setNomeDestinatario(txtRepasseDestinatario.getText());
                
//                ComboBoxFornecedorModel n = (ComboBoxFornecedorModel) cmRepasseFornecedor.getModel();
//                Fornecedor f = (Fornecedor) n.getSelectedItem();
                    
                }
                
                d.setFornecedor(new Fornecedor());
                
                if(rbDevolvido.isSelected())
                d.setDataDevolucao(new java.sql.Date(cmDataDevolucao.getDate().getTime()));
                
                if (editar == false) {
                    daoChequeRecebimento.inserir(d);
                } else if (editar == true) {
                    d.setIdChequeRecebimento(Integer.parseInt(txtRegistro.getText()));
                    daoChequeRecebimento.atualizar(d);
                    editar = false;
                }

                desabilitaBotao();
                desabilitarTextFiel();

                listaChequeRecebimento = daoChequeRecebimento.buscaTodos();
                montarFields(listaChequeRecebimento.size() - 1);
                index = listaChequeRecebimento.size() - 1;

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void jXHyperlink12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXHyperlink12ActionPerformed
        try {

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_jXHyperlink12ActionPerformed

    private void btEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEditarActionPerformed
        try {

            if (Integer.parseInt(txtRegistro.getText()) > 0) {

                editar = true;
                
                habilitaBotao();
                habilitarTextFiel();

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btEditarActionPerformed

    private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btExcluirActionPerformed
        try {

            Object[] options = {"Confirmar", "Cancelar"};

            int i = JOptionPane.showOptionDialog(null,
                    "Exclusão", "Deseja Continuar?",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                    options, options[0]);

            if (i == JOptionPane.YES_OPTION) {

                try {

                    Object[] options2 = {"Confirmar", "Cancelar"};

                    int j = JOptionPane.showOptionDialog(null,
                            "Deseja Excluir esse Registro?", "Excluir?",
                            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                            options2, options[0]);

                    if (j == JOptionPane.YES_OPTION) {

                        ChequeRecebimentoDAOImpl daoCheque = new ChequeRecebimentoDAOImpl();

                        daoCheque.remover(listaChequeRecebimento.get(index));

                        montarFields(0);
                    }

                } catch (Exception e) {
                    MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
                }

            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }//GEN-LAST:event_btExcluirActionPerformed

    private void btNaoSeiAindaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNaoSeiAindaActionPerformed

    }//GEN-LAST:event_btNaoSeiAindaActionPerformed

    private void rbDepositadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbDepositadoActionPerformed
        if (rbDepositado.isSelected() == true) {
            cmDataDeposito.setEnabled(true);
            ckCompensado.setEnabled(true);
            cmDataRepasse.setEnabled(false);
            txtRepasseDestinatario.setEnabled(false);
            cmRepasseFornecedor.setEnabled(false);
            cmDataDevolucao.setEnabled(false);
        }
    }//GEN-LAST:event_rbDepositadoActionPerformed

    private void rbEstoqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbEstoqueActionPerformed
        if (rbEstoque.isSelected() == true) {
            cmDataDeposito.setEnabled(false);
            ckCompensado.setEnabled(false);
            cmDataRepasse.setEnabled(false);
            txtRepasseDestinatario.setEnabled(false);
            cmRepasseFornecedor.setEnabled(false);
            cmDataDevolucao.setEnabled(false);
        }
    }//GEN-LAST:event_rbEstoqueActionPerformed

    private void rbRepassadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbRepassadoActionPerformed
        if (rbRepassado.isSelected() == true) {
            cmDataRepasse.setEnabled(true);
            txtRepasseDestinatario.setEnabled(true);
            cmRepasseFornecedor.setEnabled(true);
            cmDataDeposito.setEnabled(false);
            ckCompensado.setEnabled(false);
            cmDataDevolucao.setEnabled(false);
        }
    }//GEN-LAST:event_rbRepassadoActionPerformed

    private void rbDevolvidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rbDevolvidoActionPerformed
        if (rbDevolvido.isSelected() == true) {
            cmDataDevolucao.setEnabled(true);
            cmDataDeposito.setEnabled(false);
            ckCompensado.setEnabled(false);
            cmDataRepasse.setEnabled(false);
            txtRepasseDestinatario.setEnabled(false);
            cmRepasseFornecedor.setEnabled(false);
        }
    }//GEN-LAST:event_rbDevolvidoActionPerformed

    private void capturaDados() {
        try {

            ChequeRecebimentoDAOImpl daoCheque = new ChequeRecebimentoDAOImpl();

            listaChequeRecebimento = daoCheque.buscaTodos();

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    private void montarFields(int index) {
        try {

            if (listaChequeRecebimento.size() > 0) {

                ChequeRecebimento l = listaChequeRecebimento.get(index);

                txtRegistro.setText(String.valueOf(l.getIdChequeRecebimento()));
                cmDataCadastro.setDate(l.getDataCadastro());
                cmBanco.setSelectedItem(l.getBanco());
                cmDataParaBaixa.setDate(l.getDataParaBaixa());
                txtNomeEmitente.setText(l.getNomeEmitente());
                txtNumeroCheque.setText(l.getNumeroCheque());
                cmCliente.setSelectedItem(l.getCliente());
                txtValor.setText(String.valueOf(l.getValor()));
                txtCMC7.setText(l.getCMC7());
                
                cmDataDeposito.setDate(l.getDataDeposito());
                ckCompensado.setSelected(l.isCompensado());
                cmDataRepasse.setDate(l.getDataRepasse());
                txtRepasseDestinatario.setText(l.getNomeDestinatario());
                //
                cmDataDevolucao.setDate(l.getDataDevolucao());
                
                if(l.getDataDeposito() != null)
                    rbDepositado.setSelected(true);
                
                if(l.getDataRepasse()!= null)
                    rbRepassado.setSelected(true);
                
                if(l.getDataDevolucao()!= null)
                    rbDevolvido.setSelected(true);
                
                if(l.getDataDevolucao()!= null && (l.getDataRepasse()!= null) && (l.getDataDeposito() != null))
                    rbEstoque.setSelected(true);
            }

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    private void habilitaBotao() {

        btNaoSeiAinda.setEnabled(false);
        btNovo.setEnabled(false);
        btSalvar.setEnabled(true);
        btEditar.setEnabled(false);
        btExcluir.setEnabled(false);
        btCancelar.setEnabled(true);

        btPrimeiro.setEnabled(false);
        btProximo.setEnabled(false);
        btUltimo.setEnabled(false);
        btAnterior.setEnabled(false);

    }

    private void desabilitaBotao() {

        btNaoSeiAinda.setEnabled(true);
        btNovo.setEnabled(true);
        btSalvar.setEnabled(false);
        btEditar.setEnabled(true);
        btExcluir.setEnabled(true);
        btCancelar.setEnabled(false);

        btPrimeiro.setEnabled(true);
        btProximo.setEnabled(true);
        btUltimo.setEnabled(true);
        btAnterior.setEnabled(true);
    }

    private void habilitarTextFiel() {

        cmBanco.setEnabled(true);
        cmDataParaBaixa.setEnabled(true);
        txtNumeroCheque.setEnabled(true);
        txtNomeEmitente.setEnabled(true);
        cmCliente.setEnabled(true);
        txtValor.setEnabled(true);
        txtCMC7.setEnabled(true);

        rbDepositado.setEnabled(true);        
        rbDevolvido.setEnabled(true);
        rbEstoque.setEnabled(true);
        rbRepassado.setEnabled(true);

        if ((cmDataDeposito.getDate() != null) && (editar = true))
            rbDepositadoActionPerformed(null);

        if ((cmDataRepasse.getDate() != null) && (editar = true))
            rbRepassadoActionPerformed(null);
        
        if ((cmDataDevolucao.getDate() != null) && (editar = true))
            rbDevolvidoActionPerformed(null);
    }

    private void desabilitarTextFiel() {

        cmBanco.setEnabled(false);
        cmDataParaBaixa.setEnabled(false);
        txtNumeroCheque.setEnabled(false);
        txtNomeEmitente.setEnabled(false);
        cmCliente.setEnabled(false);
        txtValor.setEnabled(false);
        txtCMC7.setEnabled(false);

        rbDepositado.setEnabled(false);
        rbDevolvido.setEnabled(false);
        rbEstoque.setEnabled(false);
        rbRepassado.setEnabled(false);
        
        cmDataDeposito.setEnabled(false);
        cmDataDevolucao.setEnabled(false);
        cmDataRepasse.setEnabled(false);
        txtRepasseDestinatario.setEnabled(false);
        ckCompensado.setEnabled(false);
        cmRepasseFornecedor.setEnabled(false);
    }

    private void limparTextField() {

        txtRegistro.setText("");
        cmBanco.setSelectedIndex(0);
        cmDataParaBaixa.setDate(null);
        txtNumeroCheque.setText("");
        txtNomeEmitente.setText("");
        cmCliente.setSelectedIndex(0);
        txtValor.setText("");
        txtCMC7.setText("");
        cmDataDeposito.setDate(null);
        ckCompensado.setSelected(false);
        cmDataRepasse.setDate(null);
        txtRepasseDestinatario.setText("");
        cmDataDevolucao.setDate(null);

        rbEstoque.setSelected(true);
        
    }

    private boolean validarTextField() {

        Border border = txtRegistro.getBorder();
        Border borderCombo = cmDataCadastro.getBorder();

        ValidarCMC7 validacaoCMC = new ValidarCMC7();

        if (cmDataParaBaixa.getDate() == null) {
            cmDataParaBaixa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 1));
            return true;
        } else {
            cmDataParaBaixa.setBorder(borderCombo);
        }

        if ("".equals(txtNumeroCheque.getText())) {
            txtNumeroCheque.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            return true;
        } else {
            txtNumeroCheque.setBorder(border);
        }

        if ("".equals(txtValor.getText())) {
            txtValor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            return true;
        } else {
            txtValor.setBorder(border);
        }

        if ((validacaoCMC.ValidarCMC7(txtCMC7.getText())) == false) {
            txtCMC7.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            txtCMC7.setToolTipText("CMC7 - Número Inválido");
            return true;
        } else {
            txtCMC7.setBorder(border);
            txtCMC7.setToolTipText("CMC7");
        }

        if((rbDepositado.isSelected() == true) && (cmDataDeposito.getDate() == null)){
            cmDataDeposito.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 1));
            return true;
        }else{
            cmDataDeposito.setBorder(borderCombo);
        }
            
        if((rbRepassado.isSelected() == true) && (cmDataRepasse.getDate() == null)){
            cmDataRepasse.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 1));
            return true;
        }else{
            cmDataRepasse.setBorder(borderCombo);
        }
        
        if ((rbRepassado.isSelected() == true) && ("".equals(txtRepasseDestinatario.getText()))) {
            txtRepasseDestinatario.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 2));
            return true;
        } else {
            txtRepasseDestinatario.setBorder(border);
        }
        
        if((rbDevolvido.isSelected() == true) && (cmDataDevolucao.getDate() == null)){
            rbDevolvido.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 51), 1));
            return true;
        }else{
            rbDevolvido.setBorder(borderCombo);
        }
        
        return false;

    }

    private void carregarCombo() {
        try {

            PessoaFisicaDAOImpl daoCliente = new PessoaFisicaDAOImpl();
            BancoDAOImpl daoBanco = new BancoDAOImpl();

            List<Cliente> listaCliente = daoCliente.buscaTodos();
            cmCliente.setModel(new ComboBoxClienteModel(listaCliente));
            cmCliente.setSelectedIndex(0);

            List<Banco> listaBanco = daoBanco.buscaTodos();
            cmBanco.setModel(new ComboBoxBancoModel(listaBanco));
            cmBanco.setSelectedIndex(0);

        } catch (Exception e) {
            MessagemErro erro = new MessagemErro(new ErrorInfo("Erro no Sistema", "Não é Possível Continuar, Sistema Inativo", null, "Fatal", e, Level.WARNING, null), 1);
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFileChooser SeletorArquivo;
    private org.jdesktop.swingx.JXHyperlink btAnterior;
    private org.jdesktop.swingx.JXHyperlink btCancelar;
    private org.jdesktop.swingx.JXHyperlink btEditar;
    private org.jdesktop.swingx.JXHyperlink btExcluir;
    private org.jdesktop.swingx.JXHyperlink btNaoSeiAinda;
    private org.jdesktop.swingx.JXHyperlink btNovo;
    private org.jdesktop.swingx.JXHyperlink btPrimeiro;
    private org.jdesktop.swingx.JXHyperlink btProximo;
    private org.jdesktop.swingx.JXHyperlink btSalvar;
    private org.jdesktop.swingx.JXHyperlink btUltimo;
    private javax.swing.JCheckBox ckCompensado;
    private javax.swing.JComboBox cmBanco;
    private javax.swing.JComboBox cmCliente;
    private com.toedter.calendar.JDateChooser cmDataCadastro;
    private com.toedter.calendar.JDateChooser cmDataDeposito;
    private com.toedter.calendar.JDateChooser cmDataDevolucao;
    private com.toedter.calendar.JDateChooser cmDataParaBaixa;
    private com.toedter.calendar.JDateChooser cmDataRepasse;
    private javax.swing.JComboBox cmRepasseFornecedor;
    private javax.swing.ButtonGroup groupRadio;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JToolBar.Separator jSeparator5;
    private javax.swing.JToolBar jToolBar1;
    private org.jdesktop.swingx.JXHyperlink jXHyperlink11;
    private org.jdesktop.swingx.JXHyperlink jXHyperlink12;
    private javax.swing.JRadioButton rbDepositado;
    private javax.swing.JRadioButton rbDevolvido;
    private javax.swing.JRadioButton rbEstoque;
    private javax.swing.JRadioButton rbRepassado;
    private javax.swing.JFormattedTextField txtCMC7;
    private javax.swing.JTextField txtNomeEmitente;
    private javax.swing.JFormattedTextField txtNumeroCheque;
    private javax.swing.JTextField txtRegistro;
    private javax.swing.JTextField txtRepasseDestinatario;
    private org.jdesktop.swingx.JXHyperlink txtSair;
    private javax.swing.JFormattedTextField txtValor;
    // End of variables declaration//GEN-END:variables

}
